/*
 * LocalizationView.java
 */

package localization;


import frame.OpenMapFileFrame;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.Timer;
import java.util.TimerTask;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import objects.*;
import objects.ScanningLocation;
import org.placelab.spotter.SpotterException;

/**
 * The application's main frame.
 */
public class LocalizationView extends FrameView
{
    ScanningLocation m_location;
    Map map;
    public LocalizationView(SingleFrameApplication app) {
        super(app);

        initComponents();
        txtLocation.setText("undefined");
        this.getFrame().setResizable(false);
        btnSave.setEnabled(false);
        
        this.meuItemLoadLocationFile.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JFileChooser fileChooser = new JFileChooser();
                int returnVal = fileChooser.showOpenDialog(mainPanel);
                if(returnVal==JFileChooser.APPROVE_OPTION)
                {
                    try
                    {
                        File locationFile = fileChooser.getSelectedFile();
                        ScanningLocation m_location = new ScanningLocation().readScanningResultFromFile(locationFile);
                        m_location.printResult();
                    }
                    catch(Exception ex)
                    {
                        ex.printStackTrace();
                    }
                }
            }
        });

        //event: Create new map file
        this.menuItemNewMap.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                //CreateMapFileFrame frame = new CreateMapFileFrame();
                //frame.setVisible(true);
                //frame.setEnabled(true);
                    JFileChooser fileChooser = new JFileChooser();
                    int returnVal = fileChooser.showSaveDialog(mainPanel);
                    if(returnVal==JFileChooser.APPROVE_OPTION)
                    {
                        try
                        {
                            File blankFile = fileChooser.getSelectedFile();
                            new Map().createBlankMapFile(blankFile);
                        }
                        catch(Exception ex)
                        {
                            ex.printStackTrace();
                        }
                    }
            }
        });

        //event Open Map File
        this.menuItemOpenMapFile.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JFileChooser fileChooser = new JFileChooser();
                int returnVal = fileChooser.showOpenDialog(mainPanel);
                if(returnVal==JFileChooser.APPROVE_OPTION)
                {
                    try
                    {
                        File mapFile = fileChooser.getSelectedFile();
                        Map loadedMap = new Map().readMapFile(mapFile);
                        loadedMap.printResult();
                        OpenMapFileFrame frame = new OpenMapFileFrame(mapFile);
                        frame.setVisible(true);
                        frame.setEnabled(true);
                    }
                    catch(Exception ex)
                    {
                        ex.printStackTrace();
                    }
                }
            }
        });


        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = LocalizationApp.getApplication().getMainFrame();
            aboutBox = new LocalizationAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        LocalizationApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtLocation = new javax.swing.JTextField();
        btnStartSectionScanning = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtResult = new javax.swing.JTextArea();
        btnSave = new javax.swing.JButton();
        btnLocalize = new javax.swing.JButton();
        btnLocation = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        menuLocation = new javax.swing.JMenu();
        meuItemLoadLocationFile = new javax.swing.JMenuItem();
        menuItemMap = new javax.swing.JMenu();
        menuItemNewMap = new javax.swing.JMenuItem();
        menuItemOpenMapFile = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(localization.LocalizationApp.class).getContext().getResourceMap(LocalizationView.class);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel1.border.titleColor"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txtLocation.setText(resourceMap.getString("txtLocation.text")); // NOI18N
        txtLocation.setName("txtLocation"); // NOI18N

        btnStartSectionScanning.setText(resourceMap.getString("btnStartSectionScanning.text")); // NOI18N
        btnStartSectionScanning.setName("btnStartSectionScanning"); // NOI18N
        btnStartSectionScanning.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnStartSectionScanningMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnStartSectionScanning)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnStartSectionScanning)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel2.border.titleColor"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtResult.setColumns(20);
        txtResult.setRows(5);
        txtResult.setName("txtResult"); // NOI18N
        jScrollPane1.setViewportView(txtResult);

        btnSave.setText(resourceMap.getString("btnSave.text")); // NOI18N
        btnSave.setToolTipText(resourceMap.getString("btnSave.toolTipText")); // NOI18N
        btnSave.setName("btnSave"); // NOI18N
        btnSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSaveMouseClicked(evt);
            }
        });

        btnLocalize.setText(resourceMap.getString("btnLocalize.text")); // NOI18N
        btnLocalize.setName("btnLocalize"); // NOI18N
        btnLocalize.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLocalizeMouseClicked(evt);
            }
        });

        btnLocation.setText(resourceMap.getString("btnLocation.text")); // NOI18N
        btnLocation.setName("btnLocation"); // NOI18N
        btnLocation.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLocationMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnLocation)
                        .addGap(18, 18, 18)
                        .addComponent(btnLocalize)
                        .addGap(18, 18, 18)
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnLocalize)
                    .addComponent(btnLocation))
                .addGap(70, 70, 70))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(localization.LocalizationApp.class).getContext().getActionMap(LocalizationView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        menuLocation.setText(resourceMap.getString("menuLocation.text")); // NOI18N
        menuLocation.setName("menuLocation"); // NOI18N

        meuItemLoadLocationFile.setText(resourceMap.getString("meuItemLoadLocationFile.text")); // NOI18N
        meuItemLoadLocationFile.setName("meuItemLoadLocationFile"); // NOI18N
        menuLocation.add(meuItemLoadLocationFile);

        menuBar.add(menuLocation);

        menuItemMap.setText(resourceMap.getString("menuItemMap.text")); // NOI18N
        menuItemMap.setName("menuItemMap"); // NOI18N
        menuItemMap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemMapActionPerformed(evt);
            }
        });

        menuItemNewMap.setText(resourceMap.getString("menuItemNewMap.text")); // NOI18N
        menuItemNewMap.setName("menuItemNewMap"); // NOI18N
        menuItemMap.add(menuItemNewMap);

        menuItemOpenMapFile.setText(resourceMap.getString("menuItemOpenMapFile.text")); // NOI18N
        menuItemOpenMapFile.setName("menuItemOpenMapFile"); // NOI18N
        menuItemMap.add(menuItemOpenMapFile);

        menuBar.add(menuItemMap);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 596, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void btnStartSectionScanningMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnStartSectionScanningMouseClicked
        // TODO add your handling code here:
        if(!txtLocation.getText().equalsIgnoreCase(""))
        {
            m_location = new ScanningLocation(txtLocation.getText());
            try {
                m_location.startScanning();
            } catch (SpotterException ex) {
                Logger.getLogger(LocalizationView.class.getName()).log(Level.SEVERE, null, ex);
            }
            txtResult.setText(m_location.getResult());
            btnSave.setEnabled(true);
        }
    }//GEN-LAST:event_btnStartSectionScanningMouseClicked

    private void btnSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSaveMouseClicked
        // TODO add your handling code here:
        //m_location.writeScanningResultToFile();
        //JOptionPane.showMessageDialog(mainPanel, "Your location file has been saved successfully !","Save", JOptionPane.INFORMATION_MESSAGE);

        JFileChooser fileChooser = new JFileChooser();
        int returnVal = fileChooser.showSaveDialog(mainPanel);
        if(returnVal==JFileChooser.APPROVE_OPTION)
        {
            try
            {
                File blankFile = fileChooser.getSelectedFile();
                new ScanningLocation().createBlankFile(blankFile);
                m_location.writeScanningResultToFile(blankFile);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }
    }//GEN-LAST:event_btnSaveMouseClicked

private void btnLocalizeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLocalizeMouseClicked
    m_location = new ScanningLocation();
    
    JFileChooser fileChooser = new JFileChooser();
        int returnVal = fileChooser.showOpenDialog(mainPanel);
        if(returnVal==JFileChooser.APPROVE_OPTION)
        {
            try
            {
                File mapFile = fileChooser.getSelectedFile();
//                d.getMap().readMapFile(mapFile);
                map = new Map().readMapFile(mapFile);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }
        try {
            m_location.startScanning();
            System.out.println(m_location.getResult());
            System.out.println(map.convertMapToString());
        } catch (SpotterException ex) {
            Logger.getLogger(LocalizationView.class.getName()).log(Level.SEVERE, null, ex);
        }
     MyDetector d = new MyDetector(m_location,map);
     
     txtResult.setText(d.startLocalization());
    
     
    // TODO add your handling code here:
}//GEN-LAST:event_btnLocalizeMouseClicked

private void menuItemMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemMapActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_menuItemMapActionPerformed

private void btnLocationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLocationMouseClicked
    JFileChooser fileChooser = new JFileChooser();
        int returnVal = fileChooser.showOpenDialog(mainPanel);
        if(returnVal==JFileChooser.APPROVE_OPTION)
        {
            try
            {
                File mapFile = fileChooser.getSelectedFile();
//                d.getMap().readMapFile(mapFile);
                m_location = new ScanningLocation().readScanningResultFromFile(mapFile);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }
       // m_location.getM_APList().remove(0);
        txtResult.setText(m_location.getResult());
    // TODO add your handling code here:
}//GEN-LAST:event_btnLocationMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLocalize;
    private javax.swing.JButton btnLocation;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnStartSectionScanning;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu menuItemMap;
    private javax.swing.JMenuItem menuItemNewMap;
    private javax.swing.JMenuItem menuItemOpenMapFile;
    private javax.swing.JMenu menuLocation;
    private javax.swing.JMenuItem meuItemLoadLocationFile;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField txtLocation;
    private javax.swing.JTextArea txtResult;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
